package com.pms.service;

import java.util.List;

import com.pms.dao.ContactDao;
import com.pms.entity.Contact;





import com.pms.util.DateUtil;
import com.pms.util.PKUtil;
import com.pms.util.Page;

public class ContactService {
	ContactDao dao=new ContactDao();
	public Contact save(String name,String company,String tel,String phone,String email,String address,String mainWeb,String blog,String projectId,String desc){
		
		Contact contact=new Contact();
		contact.setContactId(PKUtil.getPkId());
		contact.setContactName(name);
		contact.setCompany(company);
		contact.setTel(tel);
		contact.setPhone(phone);
		contact.setEmail(email);
		contact.setAddress(address);
		contact.setMainWeb(mainWeb);
		contact.setBlog(blog);
		contact.setCreateTime(DateUtil.getNow());
		contact.setDesc(desc);
		contact.setProjectId(projectId);
		
		dao.save(contact);
		
		return contact;
		
	}
	public Page<Contact> findAll(String projectId,int pageNum){
		Page<Contact> page = new Page<Contact>(5,dao.getCount(projectId),pageNum);
		
		
		Page<Contact> list=dao.FindAll(projectId,page);
		
		return list;
		
	}
	
	public List<Contact> findAll(String projectId){
		return dao.FindAll(projectId);
		
	}
	
	
	
	public Contact findContactById(String contactId){
		ContactDao dao=new ContactDao();
		return dao.FindContactById(contactId);
		
	}
	public void updateContact(String contactName,String company,String tel,String phone,String address,String mainWeb,String email,String blog,String desc,String contactId) {
		Contact contact=new Contact();
		//contact.setContactId(contactId);
		contact.setContactName(contactName);
		contact.setCompany(company);
		contact.setTel(tel);
		contact.setPhone(phone);
		contact.setAddress(address);
		contact.setMainWeb(mainWeb);
		contact.setEmail(email);
		contact.setBlog(blog);
		contact.setDesc(desc);
		contact.setContactId(contactId);
		dao.updateContact(contact);
	}
	public void delContact(String contactId){
		
		dao.delContact(contactId);
	}
	 
	 public Contact findByName(String contactName){
		 return dao.findByName(contactName);
	 }
	 
		 
		 
	 
	
}
